#include<stdio.h>
#include<stdlib.h>
#include<string.h>


struct LinkNode{
    int num;
    struct LinkNode* next;
};


// 静态链表
void test1(){
    struct LinkNode node1 = {10,NULL};
    struct LinkNode node2 = {20,NULL};
    struct LinkNode node3 = {30,NULL};
    struct LinkNode node4 = {40,NULL};
    struct LinkNode node5 = {50,NULL};

    // 建立关系
    node1.next = &node2;
    node2.next = &node3;
    node3.next = &node4;
    node4.next = &node5;

    // 遍历链表
    struct LinkNode * pCurrent = &node1;  
    while(pCurrent!=NULL){
        printf("num:%d\n", pCurrent->num);
        pCurrent = pCurrent->next;
    }
}

// 动态链表  栈上
void test2(){
    struct LinkNode * node1 = malloc(sizeof(struct LinkNode));  
    struct LinkNode * node2 = malloc(sizeof(struct LinkNode));  
    struct LinkNode * node3 = malloc(sizeof(struct LinkNode));  
    struct LinkNode * node4 = malloc(sizeof(struct LinkNode));  
    struct LinkNode * node5 = malloc(sizeof(struct LinkNode));  
    
    node1->num = 100;
    node2->num = 200;
    node3->num = 300;
    node4->num = 400;
    node5->num = 500;

    // 建立关系
    node1->next = node2;
    node2->next = node3;
    node3->next = node4;
    node4->next = node5;
    node5->next = NULL;

    struct LinkNode * pCurrent = node1;
    while(pCurrent!=NULL){
        printf("num:%d\n", pCurrent->num);
        pCurrent = pCurrent->next;
    }

}

void main(){
    // test1();
    test2();
}